package object2;

/**
 * 多态
 */
public class Polymorphic {

    public static void main(String[] args) {

        /*
            1)方法或对象具有多种形态。是面向对象的第三大特征，建立在封装和继承上
         */
    }
}

class Animals {

    private String name;

    public Animals(String name){
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

class Bone extends Food {

    public Bone(String name) {
        super(name);
    }

}

class Fish extends Food {

    public Fish(String name) {
        super(name);
    }

}

class Food {

    private String name;

    public Food(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}

class Master {

    private String name;

    public Master(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    //使用多态机制，可以统一地管理主人喂食问题
    //animals编译类型是Animals，可以指向Animal子类的对象
    //food编译类型是Food，可以指向Food子类的对象
    public void feed(Animals animals, Food food) {
        System.out.println("主人 " + name + "给" + animals.getName() + "吃" + food.getName());
    }
}
